from flask import session, current_app
from flask_script import Manager
from flask_migrate import  MigrateCommand, Migrate
import logging

from info import create_app, db, models
from info.models import User

app = create_app('developmentconfig')
manager = Manager(app)
Migrate(app,db)
manager.add_command("db",MigrateCommand)

#
@manager.option('-n','-name',dest='name')
@manager.option('-p','-password',dest='name')
def createsuperuser(name,password):
    if not all([name,password]):
        return "参数错误"
    user =User()
    user.nick_name= name
    user.password = password
    user.is_admin =True
    user.mobile = name
    try:
        db.session.add(user)
        db.session.commit()
    except Exception as e:
        current_app.logger.error(e)
        db.session.rollback()
    print('成功')



if __name__ == '__main__':
    manager.run()

